package controller.link.game;

import view.client.Console;
import view.client.PanelGame;
import java.io.Serializable;
import javax.swing.JTextArea;
import controller.Link;
import model.game.HealCenter;
import model.game.NPC;
import model.game.Player;
import model.game.Seller;
import model.Attendant;
import model.Server;

public class ChallengeNpc implements Link, Serializable {

    private NPC npc;
    private Player playerWhoAsked;

    public ChallengeNpc(NPC npc, Player playerWhoAsked) {
        this.npc = npc;
        this.playerWhoAsked = playerWhoAsked;
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        if (npc instanceof HealCenter) {
            HealCenter hc = (HealCenter) npc;
            hc.heal(playerWhoAsked, at, server);
        } else if (npc instanceof Seller) {
            Seller seller = (Seller) npc;
            seller.showInventory(server, at);
        }
        at.send((Link) this);
    }

    @Override
    public void clientUse(Console console) {
        PanelGame pg = console.getPg();
        JTextArea csl = pg.getTxtArea();
        csl.append(npc.getName() + ": " + npc.getTalk() + "\n");
        pg.getBtnEnviar().setEnabled(true);
        pg.getListAction().setEnabled(true);
    }
}
